package test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);

        Socket socket = ss.accept();

        String name = UUID.randomUUID().toString().replace("-","");
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Java_11_23\\"+name+".png"));
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());

        byte[] bytes = new byte[1024];
        int len;
        while((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
        bos.flush();

        String str = "传输完成";
        OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
        osw.write(str);
        osw.flush();


        socket.close();
        ss.close();
    }
}
